package com.kang.bean.bot;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

/**
 * @program: service
 * @description: 游戏地图
 * @author: K.faWu
 * @create: 2022-05-09 13:55
 **/
@Data
public class WarMap implements Serializable {
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    private String name;
    private String code;
    private Integer x;
    private Integer y;
    private String type;
    private String accountCode;
    private String groupCode;
    //防守士兵数量
    private Integer soldierNum = 0;
    //防守士兵上限
    private Integer soldierMax = 0;
    //人口上限
    private Integer proMax = 0;
    //农民数量
    private Integer farmerNum = 0;
    //伐木工上限
    private Integer woodMax = 0;
    //伐木工数量
    private Integer woodNum = 0;
    //矿工上限
    private Integer minerMax = 0;
    private Integer minerNum = 0;
    //建筑类型
    private Integer defenseType;
    //建筑等级
    private Integer defenseLv;

    /**
     * 空构造函数
     */
    public WarMap(){}


    public static void initWarMap(WarMap warMap){
        warMap.setProMax(100);
        warMap.setFarmerNum(100);
        warMap.setSoldierMax(50);
        warMap.setSoldierNum(0);
        warMap.setWoodMax(50);
        warMap.setWoodNum(0);
        warMap.setMinerMax(50);
        warMap.setMinerNum(0);
        warMap.setDefenseType(1);
        warMap.setDefenseLv(1);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        WarMap warMap = (WarMap) o;
        return Objects.equals(id, warMap.id) && Objects.equals(name, warMap.name) && Objects.equals(code, warMap.code) && Objects.equals(x, warMap.x) && Objects.equals(y, warMap.y) && Objects.equals(type, warMap.type) && Objects.equals(accountCode, warMap.accountCode) && Objects.equals(groupCode, warMap.groupCode);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, code, x, y, type, accountCode, groupCode);
    }

    public Integer getSum() {
        return this.getSoldierNum() + this.getWoodNum() + this.getMinerNum() + this.getFarmerNum();
    }

    /**
     *
     * @return 当前城池所能容纳的最多人数
     */
    public Integer getMax() {
        return this.getSoldierMax() + this.getWoodMax() + this.getMinerMax() + this.getProMax();
    }
}
